namespace OrderingSystem.Core.Entities
{
    public enum OrderStatus
    {
        /// <summary>
        /// 待处理
        /// </summary>
        Pending = 0,

        /// <summary>
        /// 已接单
        /// </summary>
        Accepted = 1,

        /// <summary>
        /// 制作中
        /// </summary>
        Processing = 2,

        /// <summary>
        /// 已完成
        /// </summary>
        Completed = 3,

        /// <summary>
        /// 已取消
        /// </summary>
        Cancelled = 4,

        /// <summary>
        /// 已拒绝
        /// </summary>
        Rejected = 5
    }

    public static class OrderStatusExtensions
    {
        public static bool CanTransitionTo(this OrderStatus currentStatus, OrderStatus newStatus)
        {
            return (currentStatus, newStatus) switch
            {
                // 待处理状态可以转换到任何状态（除了完成）
                (OrderStatus.Pending, OrderStatus.Accepted) => true,
                (OrderStatus.Pending, OrderStatus.Rejected) => true,
                (OrderStatus.Pending, OrderStatus.Cancelled) => true,

                // 已接单状态只能转换到制作中或取消
                (OrderStatus.Accepted, OrderStatus.Processing) => true,
                (OrderStatus.Accepted, OrderStatus.Cancelled) => true,

                // 制作中状态只能转换到完成或取消
                (OrderStatus.Processing, OrderStatus.Completed) => true,
                (OrderStatus.Processing, OrderStatus.Cancelled) => true,

                // 其他状态都是终态，不能再转换
                _ => false
            };
        }

        public static string ToDisplayName(this OrderStatus status)
        {
            return status switch
            {
                OrderStatus.Pending => "待处理",
                OrderStatus.Accepted => "已接单",
                OrderStatus.Processing => "制作中",
                OrderStatus.Completed => "已完成",
                OrderStatus.Cancelled => "已取消",
                OrderStatus.Rejected => "已拒绝",
                _ => "未知状态"
            };
        }
    }
} 